622B - The Time - CodeForces Solution


implementation *900

Please click on ads to support us..

Python Code:

import sys, os
import math
from collections import Counter

TC = False

def solve():
    h,m = str(input()).split(':')
    add_min = int(input())
    add_h = add_min//60
    add_m = add_min%60
    h = int(h) + add_h
    m = int(m) + add_m
    while m >= 60:
        h += 1
        m -= 60
    while h >= 24:
        h -= 24
    print('{:02d}:{:02d}'.format(h,m))


        

if os.path.exists('input.txt'):
    debug = True
    sys.stdin = open("input.txt","r")
    
if TC:
    for _ in range(int(input())):
        solve()
else:
    solve()

C++ Code:

#include<bits/stdc++.h>
using namespace std;
void print_time(int h,int m){
	if(h<10) cout<<0;
	cout<<h<<":";
	if(m<10) cout<<0;
	cout<<m;
}
void solve(){
	int h,m,a;
    char c;
    cin>>h>>c>>m>>a;
    while(a--){
    	m++;
    	if(m==60) h++,m=0;
    	if(h==24) h=0;
 	}
 	print_time(h,m);
}
int main(){
	cin.tie(0);
	ios::sync_with_stdio(0);
    int tc=1; //cin>>tc;
	while(tc--) solve();
    return 0;
}
//ACplease!!!
/*  printf("                                                                \n");
	printf("                                                                \n");
	printf("       * * *               * * *             * * *             * * *            \n");
	printf("     *       *           *       *         *      *          *       *         \n");
	printf("    *        *          *         *       *        *        *         *        \n");
	printf("            *           *         *                *                  *      \n");
	printf("           *            *         *               *                  *     \n");
	printf("          *             *         *              *                  *       \n");
	printf("         *              *         *             *                  *            \n");
	printf("        *               *         *           *                  *            \n");
	printf("      *                  *       *          *                  *           \n");
	printf("    * * * * * * *          * * *          * * * * * * *      * * * * * * *                           \n");
*/    


Comments

Submit
0 Comments
More Questions

62. Unique Paths
50. Pow(x, n)
43. Multiply Strings
34. Find First and Last Position of Element in Sorted Array
33. Search in Rotated Sorted Array
17. Letter Combinations of a Phone Number
5. Longest Palindromic Substring
3. Longest Substring Without Repeating Characters
1312. Minimum Insertion Steps to Make a String Palindrome
1092. Shortest Common Supersequence
1044. Longest Duplicate Substring
1032. Stream of Characters
987. Vertical Order Traversal of a Binary Tree
952. Largest Component Size by Common Factor
212. Word Search II
174. Dungeon Game
127. Word Ladder
123. Best Time to Buy and Sell Stock III
85. Maximal Rectangle
84. Largest Rectangle in Histogram
60. Permutation Sequence
42. Trapping Rain Water
32. Longest Valid Parentheses
Cutting a material
Bubble Sort
Number of triangles
AND path in a binary tree
Factorial equations
Removal of vertices
Happy segments